create_order(self, account_id, **params)
In [1]:
from datetime import datetime, timedelta
import pandas as pd
import oandapy
import configparser
config = configparser.ConfigParser()
config.read('../config/config_v1.ini')
account_id = config['oanda']['account_id']
api_key = config['oanda']['api_key']
oanda = oandapy.API(environment="practice",
access_token=api_key)
In [2]:
trade_expire = datetime.now() + timedelta(days=1)
trade_expire = trade_expire.isoformat("T") + "Z"
trade_expire
Out[2]:
For a detailed explanation of the above, please refer to Rates Information.
In [3]:
response = oanda.create_order(account_id,
instrument = "AUD_USD",
units=1000,
side="buy",
type="limit",
price=0.7420,
expiry=trade_expire)
print(response)
In [4]:
pd.Series(response["orderOpened"])
Out[4]:
In [5]:
order_id = response["orderOpened"]['id']
get_orders(self, account_id, **params)
In [6]:
response = oanda.get_orders(account_id)
print(response)
In [7]:
pd.DataFrame(response['orders'])
Out[7]:
get_order(self, account_id, order_id, **params)
In [8]:
response = oanda.get_orders(account_id)
id = response['orders'][0]['id']
In [9]:
oanda.get_order(account_id, order_id=id)
Out[9]:
modify_order(self, account_id, order_id, **params)
In [10]:
response = oanda.get_orders(account_id)
id = response['orders'][0]['id']
In [11]:
oanda.modify_order(account_id, order_id=id, price=0.7040)
Out[11]:
close_order(self, account_id, order_id, **params)
In [12]:
response = oanda.get_orders(account_id)
id = response['orders'][0]['id']
In [13]:
oanda.close_order(account_id, order_id=id)
Out[13]:
Now when we check the orders. The above order has been closed and removed without being filled. There is only one outstanding order now.
In [14]:
oanda.get_orders(account_id)
Out[14]: